
<!-- 主页面开始 -->
<div id="main" class="main" >
    <!-- 主体内容  -->
    <div class="content" >
        <div class="title">新建申购单 </div>
        <!--  功能操作区域  -->
        <div class="operate" >
            <!-- 查询区域 -->
            <div class="fRig">

            </div>
            <!-- 高级查询区域 -->
            <div  id="searchM" class=" none search cBoth" >
            </div>
            </FORM>
        </div>
        <!-- 功能操作区域结束 -->
        <!-- 列表显示区域  -->
        <div class="list" >
        <form  action="__URL__/insert" method="post" enctype="application/x-www-form-urlencoded" name="shenggou" id="shenggou" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone)">
<table width="100%" border="0">
<tr><td>申购单标题</td><td><input name="title" type="text" /></td>
  <td>申购部门 </td>
  <td><input type="text" name="department" id="department" /></td><td>申购单编号
    </td><td><input name="number" type="text" /></td>
  <td>采购类别<select name="category">
    <option value="客用产品采购">客用产品采购</option>
    <option value="院用耗材采购">院用耗材采购</option>
    <option value="布草用品采购">布草用品采购</option>
    <option value="固定资产采购">固定资产采购</option>
    <option value="广告用品采购">广告用品采购</option>
    <option value="其它用品采购">其它用品采购</option>
  </select></td>  
    </tr>
 </table>
 <br />
<table width="100%" border="0">
  <tr>
    <td>序号</td>
    <td align='center'>选择系列</td>
    <td>选择品名（无名称则直接填写）</td>
    <td>规格</td>
    <td>编号</td>
	<td>选择</td>
    <td>申购预算</td>
    <td>申购数量</td>
    <td>备注说明</td>
    <td><input type="button"  id="purchase_additem" value="增加条目"   /></td>
  </tr>
  <!--申购数据-->
  <tr class="product" style="display:none;" id="0"></tr>
  <volist name="list" id="data">
  <tr class="product" id="{$data.id}">
  <input type="hidden" name="items[{$data.id}][id]"  value="{$data.id}"/>
  <input type="hidden" name="items[{$data.id}][category]"  value="{$data.category}"/>
  <input type="hidden" name="items[{$data.id}][product_name]"  value="{$data.product_name}"/>
  <input type="hidden" name="items[{$data.id}][unit]"  value="{$data.unit}"/>
  <input type="hidden" name="items[{$data.id}][product_code]"  value="{$data.product_code}"/>
    <td><span class="order">{$i}</span></td>
    <td>{$data.category}</td>
    <td>{$data.product_name}</td>
    <td>{$data.unit}</td>
    <td>{$data.product_code}</td>
    <td><input type="hidden" name="items[{$data.id}][purchase_price]" value="{$data.purchase_price}"/><input type="text" name="items[{$data.id}][money]" value="{$data.purchase_price}"/>元</td>
    <td><input type="text" name="items[{$data.id}][number]"  value="{$data.number}"/></td>
    <td><input type="text" name="items[{$data.id}][note]"  value=""/></td>
    <td><input type="button"  value="移除条目"  onclick="removeitem({$data.id})"/></td>
  </tr>
  </volist>
  <tr class="goods" style="display:none;"></tr>
  <tr class="sum">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td></td>
    <td>合计</td>
	<td><font id="purchase_showNum" color='red'>0</font>元&nbsp;</td>
    <td><span id="summoney">&nbsp;</span></td>
    <td><span id="sumnumber">&nbsp;</span></td>
    <td>&nbsp;</td>
  </tr>  
</table>
<br />
<table width="100%" border="0">
<tr><td>其他说明</td></tr>
<tr><td><textarea name="note" cols="100" rows=""></textarea></td></tr>
</table>
<p>申购人姓名<input name="applicant" type="text" value="{$Think.session.loginUserName}"  />
申购周期<input type="text" class="date" format="yyyy-MM-dd HH:mm:ss" name="starttime" />
~<input type="text" class="date" format="yyyy-MM-dd HH:mm:ss" name="endtime" />
</p>
<p align="right"><input type="submit" name="submit" value="提交" />
  <input type="reset" name="button" id="button" value="重置" />
</p>
</form>
        </div>
        <!--  分页显示区域 -->
        <div class="page"></div>
        <!-- 列表显示区域结束 -->       
  </div>
    <!-- 主体内容结束 -->
</div>
<!-- 主页面结束 -->

<script type="text/javascript">
 var select;
 var del;
(function(){
  var html='';
  for(var i=1;i<=5;i++)
  {
    html+='<tr class="goods" id="purchase_goods_'+i+'"><td><span class="order"></span></td><td><input id="purchase_brand_'+i+'" class="textInput" type="text" name="items[][category]"/></td><td><input id="purchase_product_name_'+i+'" class="textInput" type="text" name="items[][product_name]"/></td><td><input id=purchase_unit_'+i+'" class="textInput" type="text" name="items[][unit]"/></td><td><input class="textInput" type="text" name="items[][product_code]" onblur="sendAjax(this.value,'+i+',responsePurchase)"/></td><td><input id="purchase_checkbox_'+i+'" class="textInputch" type="checkbox" name="items[][addname]" value="'+i+'"/></td><td><input id="purchase_price_'+i+'" class="textInput" type="text" name="items[][purchase_price]"/></td><td><input id="purchase_goodsnumber_'+i+'" class="textInput" type="text" name="items[][number]"/></td><td><input class="textInput" type="text" name="items[][note]"/></td><td><input  id="purchase_remove_'+i+'" class="remove" val="'+i+'" type="button"  value="移除条目"  /></td></tr>';
	}
	num=i;
    $('.goods:last').after(html);
	
	for(var i=1;i<=5;i++)
     {
	     $("#purchase_checkbox_"+i).bind('click', function() {
  return select(this);
      });
	      $("#purchase_remove_"+i).bind('click', function() {
  return del(this);
  });
  
	  }
	refreshorder();
    
	//新增条目
	$("#purchase_additem").click(function(){
	
	var html='<tr class="goods" id="purchase_goods_'+num+'"><td><span class="order"></span></td><td><input id="purchase_brand_'+num+'" class="textInput" type="text" name="items[][category]"/></td><td><input id="purchase_product_name_'+num+'" class="textInput" type="text" name="items[][product_name]"/></td><td><input id="purchase_unit_'+num+'" class="textInput" type="text" name="items[][unit]"/></td><td><input class="textInput" type="text" name="items[][product_code]" onblur="sendAjax(this.value,'+num+',responsePurchase)"/></td><td><input id="purchase_checkbox_'+num+'" class="textInputch" type="checkbox" name="items[][addname]" value="'+num+'"/></td><td><input id="purchase_price_'+num+'" class="textInput" type="text" name="items[][purchase_price]"/></td><td><input id="purchase_goodsnumber_'+num+'" class="textInput" type="text" name="items[][number]"/></td><td><input class="textInput" type="text" name="items[][note]"/></td><td><input id="purchase_remove_'+num+'" type="button"  class="remove" val="'+num+'" value="移除条目"  /></td></tr>';
	
	$('.goods:last').after(html);
		 $("#purchase_checkbox_"+num).bind('click', function() {
  return select(this);
      });
	 $("#purchase_remove_"+num).bind('click', function() {
  return del(this);
  });
  num+=1;
	refreshorder();
	
	});
	
	//价格计算
	var totalPrice=0;
	select=function(o)
	{
	i=o.value;
	var goodsNum=parseInt($.trim($("#purchase_goodsnumber_"+i).val()));
	var goodsPrice=parseFloat($.trim($("#purchase_price_"+i).val()));
	
	if(o.checked && goodsNum>0 && goodsPrice>0)
	totalPrice+=goodsNum*goodsPrice;
	else if(!o.checked && goodsNum>0 && goodsPrice>0)
	totalPrice-=goodsNum*goodsPrice;
	else
	{
	alert('商品数量或价格填写不符合要求');
	o.checked=false;
	return;
	}
	//alert('选择中的是'+totalPrice);
	$("#purchase_showNum").html(totalPrice);
	}
	
	//移除条目
	del=function(p)
	{
	p_id=p.getAttribute('val');
    val=$.trim($("#purchase_goodsnumber_"+p_id).val());
	pri=$.trim($("#purchase_price_"+p_id).val());
	//alert($("#checkbox_"+$(this).attr("val")).attr("checked"));
	if(parseInt(val)>0 && val !='' && pri!='' && parseFloat(pri)>0 && $("#purchase_checkbox_"+p_id).attr("checked"))
	{
	//alert('减去之前是'+totalPrice);
	totalPrice-=parseInt(val)*parseFloat(pri);
	//alert('减去之后是'+totalPrice);
	$("#purchase_showNum").html(totalPrice);
	}
	$("#purchase_goods_"+p_id).remove();
	refreshorder();
	}
	
	
})();
</script>